package com.hyfrogx.modules.information.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hyfrogx.common.utils.QueryExt;
import com.hyfrogx.modules.information.dao.HyInformationOrderDao;
import com.hyfrogx.modules.information.entity.HyInformationEntity;
import com.hyfrogx.modules.information.entity.HyInformationOrderEntity;
import com.hyfrogx.modules.information.entity.HyInformationVerifyEntity;
import com.hyfrogx.modules.information.service.HyInformationOrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

/**
 * @author liubin
 * @date 2019/10/21 13:38
 */
@Slf4j
@Service("hyInformationOrderService")
public class HyInformationOrderServiceImpl extends ServiceImpl<HyInformationOrderDao, HyInformationOrderEntity> implements HyInformationOrderService {

  @Override
  public String createOrderId() {
    // 最大支持1-9个集群机器部署
    int machineId = 1;
    int hashCodeV = UUID.randomUUID().toString().hashCode();
    // 有可能是负数
    if (hashCodeV < 0) {
      hashCodeV = -hashCodeV;
    }
    // 0 代表前面补充0
    // 4 代表长度为4
    // d 代表参数为正数型
    return machineId + String.format("%013d", hashCodeV);  }

  @Override
  public Page getAllRecord(QueryExt query) {
    Map map = new HashMap(16);
    map.putAll(query.getCondition());
    List<HyInformationOrderEntity> result = this.baseMapper.getAllRecord(query,map);
    query.setRecords(result);
    return query;
  }
}
